/*
package cloud.xlh.infrastructure.service_register_recoverd.service.impl;

import cloud.xlh.infrastructure.service_register_recoverd.MyRegisterCenterProperties;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.naming.utils.NamingUtils;
import com.alibaba.nacos.api.selector.AbstractSelector;
import com.alibaba.nacos.client.naming.beat.BeatInfo;
import com.alibaba.nacos.client.naming.beat.BeatReactor;
import com.alibaba.nacos.client.naming.core.EventDispatcher;
import com.alibaba.nacos.client.naming.core.HostReactor;
import com.alibaba.nacos.client.naming.net.NamingProxy;
import com.alibaba.nacos.client.naming.utils.InitUtils;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Properties;

import static com.alibaba.nacos.api.common.Constants.DEFAULT_HEART_BEAT_INTERVAL;

*/
/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2022/10/20 17:21
 * @ Description:
 *//*

@Configuration
public class MyNacosNamingService implements NamingService{
    private static final String DEFAULT_PORT = "8080";
    private String namespace;
    private String endpoint;
    private String serverList;
    private String cacheDir;
    private String logName;
    private HostReactor hostReactor;
    private BeatReactor beatReactor;
    private EventDispatcher eventDispatcher;
    private NamingProxy serverProxy;


    public MyNacosNamingService(MyRegisterCenterProperties myRegisterCenterProperties) {
        this.init(myRegisterCenterProperties);
    }

    private void init(MyRegisterCenterProperties myRegisterCenterProperties) {
        this.namespace = "public";
        //this.initServerAddr(properties);
        this.serverList = myRegisterCenterProperties.getServerAddress();
        this.endpoint = "";

        InitUtils.initWebRootContext();

        this.cacheDir = "C:\\Users\\xulehuang\\nacos\\naming\\public";
        this.logName = "naming.log";
        this.eventDispatcher = new EventDispatcher();
        this.serverProxy = new NamingProxy(this.namespace, this.endpoint, this.serverList);
        Properties properties = new Properties();
        properties.put("encode" , "UTF-8");
        properties.put("serverAddr" , this.serverList);
        //this.serverProxy.setProperties(properties);
        this.beatReactor = new BeatReactor(this.serverProxy, this.initClientBeatThreadCount(properties));
        this.hostReactor = new HostReactor(this.eventDispatcher, this.serverProxy, this.cacheDir, this.isLoadCacheAtStart(properties), this.initPollingThreadCount(properties));
    }

    private int initClientBeatThreadCount(Properties properties) {
        return properties == null ? UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT : NumberUtils.toInt(properties.getProperty("namingClientBeatThreadCount"), UtilAndComs.DEFAULT_CLIENT_BEAT_THREAD_COUNT);
    }
    private boolean isLoadCacheAtStart(Properties properties) {
        boolean loadCacheAtStart = false;
        if (properties != null && StringUtils.isNotEmpty(properties.getProperty("namingLoadCacheAtStart"))) {
            loadCacheAtStart = BooleanUtils.toBoolean(properties.getProperty("namingLoadCacheAtStart"));
        }

        return loadCacheAtStart;
    }

    private int initPollingThreadCount(Properties properties) {
        return properties == null ? UtilAndComs.DEFAULT_POLLING_THREAD_COUNT : NumberUtils.toInt(properties.getProperty("namingPollingThreadCount"), UtilAndComs.DEFAULT_POLLING_THREAD_COUNT);
    }
    @Override
    public void registerInstance(String serviceName, String ip, int port) throws NacosException {
    this.registerInstance(serviceName , ip , port , "DEFAULT");
    }

    @Override
    public void registerInstance(String s, String s1, String s2, int i) throws NacosException {

    }

    @Override
    public void registerInstance(String serviceName, String ip , int port, String clusterName) throws NacosException {
        this.registerInstance(serviceName, "DEFAULT_GROUP", ip, port, clusterName);
    }

    @Override
    public void registerInstance(String serviceName, String groupName, String ip, int port, String clusterName) throws NacosException {
        Instance instance = new Instance();
        instance.setIp(ip);
        instance.setPort(port);
        //权重
        instance.setWeight(1.0D);
        instance.setClusterName(clusterName);
        this.registerInstance(serviceName, groupName, instance);
    }

    @Override
    public void registerInstance(String s, Instance instance) throws NacosException {

    }

    @Override
    public void registerInstance(String serviceName, String groupName, Instance instance) throws NacosException {
        if (instance.isEphemeral()) {
            BeatInfo beatInfo = new BeatInfo();
            beatInfo.setServiceName(NamingUtils.getGroupedName(serviceName, groupName));
            beatInfo.setIp(instance.getIp());
            beatInfo.setPort(instance.getPort());
            beatInfo.setCluster(instance.getClusterName());
            beatInfo.setWeight(instance.getWeight());
            beatInfo.setMetadata(instance.getMetadata());
            beatInfo.setScheduled(false);
            long instanceInterval = instance.getInstanceHeartBeatInterval();
            beatInfo.setPeriod(instanceInterval == 0L ? DEFAULT_HEART_BEAT_INTERVAL : instanceInterval);
            this.beatReactor.addBeatInfo(NamingUtils.getGroupedName(serviceName, groupName), beatInfo);
        }

        this.serverProxy.registerService(NamingUtils.getGroupedName(serviceName, groupName), groupName, instance);

    }

    @Override
    public void deregisterInstance(String s, String s1, int i) throws NacosException {

    }

    @Override
    public void deregisterInstance(String s, String s1, String s2, int i) throws NacosException {

    }

    @Override
    public void deregisterInstance(String s, String s1, int i, String s2) throws NacosException {

    }

    @Override
    public void deregisterInstance(String s, String s1, String s2, int i, String s3) throws NacosException {

    }

    @Override
    public void deregisterInstance(String s, Instance instance) throws NacosException {

    }

    @Override
    public void deregisterInstance(String s, String s1, Instance instance) throws NacosException {

    }

    @Override
    public List<Instance> getAllInstances(String s) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> getAllInstances(String s, String s1) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> getAllInstances(String s, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> getAllInstances(String s, String s1, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> getAllInstances(String s, List<String> list) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> getAllInstances(String s, String s1, List<String> list) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> getAllInstances(String s, List<String> list, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> getAllInstances(String s, String s1, List<String> list, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, String s1, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, boolean b, boolean b1) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, String s1, boolean b, boolean b1) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, List<String> list, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, String s1, List<String> list, boolean b) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, List<String> list, boolean b, boolean b1) throws NacosException {
        return null;
    }

    @Override
    public List<Instance> selectInstances(String s, String s1, List<String> list, boolean b, boolean b1) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s, String s1) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s, boolean b) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s, String s1, boolean b) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s, List<String> list) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s, String s1, List<String> list) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s, List<String> list, boolean b) throws NacosException {
        return null;
    }

    @Override
    public Instance selectOneHealthyInstance(String s, String s1, List<String> list, boolean b) throws NacosException {
        return null;
    }

    @Override
    public void subscribe(String s, EventListener eventListener) throws NacosException {

    }

    @Override
    public void subscribe(String s, String s1, EventListener eventListener) throws NacosException {

    }

    @Override
    public void subscribe(String s, List<String> list, EventListener eventListener) throws NacosException {

    }

    @Override
    public void subscribe(String s, String s1, List<String> list, EventListener eventListener) throws NacosException {

    }

    @Override
    public void unsubscribe(String s, EventListener eventListener) throws NacosException {

    }

    @Override
    public void unsubscribe(String s, String s1, EventListener eventListener) throws NacosException {

    }

    @Override
    public void unsubscribe(String s, List<String> list, EventListener eventListener) throws NacosException {

    }

    @Override
    public void unsubscribe(String s, String s1, List<String> list, EventListener eventListener) throws NacosException {

    }

    @Override
    public ListView<String> getServicesOfServer(int i, int i1) throws NacosException {
        return null;
    }

    @Override
    public ListView<String> getServicesOfServer(int i, int i1, String s) throws NacosException {
        return null;
    }

    @Override
    public ListView<String> getServicesOfServer(int i, int i1, AbstractSelector abstractSelector) throws NacosException {
        return null;
    }

    @Override
    public ListView<String> getServicesOfServer(int i, int i1, String s, AbstractSelector abstractSelector) throws NacosException {
        return null;
    }

    @Override
    public List<ServiceInfo> getSubscribeServices() throws NacosException {
        return null;
    }

    @Override
    public String getServerStatus() {
        return null;
    }
}
*/
